package com.example.config;

import org.activiti.spring.SpringAsyncExecutor;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.activiti.spring.boot.AbstractProcessEngineAutoConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;
import java.io.IOException;

/**
 * @Deacription 重写SpringProcessEngineConfiguration配置
 * @Author baohuajie
 * @Date 2021/1/17 15:02
 * @Version 1.0
 **/
@Configuration
public class ActivitiConfig extends AbstractProcessEngineAutoConfiguration {

    @Autowired
    private SpringAsyncExecutorProperties springAsyncExecutorProperties;

    @Bean
    public SpringProcessEngineConfiguration springProcessEngineConfiguration(
            DataSource dataSource,
            PlatformTransactionManager transactionManager,
            SpringAsyncExecutor springAsyncExecutor) throws IOException {

        springAsyncExecutor.setCorePoolSize(springAsyncExecutorProperties.getCorePoolSize());
        springAsyncExecutor.setMaxPoolSize(springAsyncExecutorProperties.getMaxPoolSize());
        springAsyncExecutor.setAsyncJobLockTimeInMillis(springAsyncExecutorProperties.getAsyncJobLockTimeInMillis());
        springAsyncExecutor.setTimerLockTimeInMillis(springAsyncExecutorProperties.getTimerLockTimeInMillis());
        springAsyncExecutor.setDefaultAsyncJobAcquireWaitTimeInMillis(springAsyncExecutorProperties.getDefaultAsyncJobAcquireWaitTimeInMillis());
        springAsyncExecutor.setDefaultTimerJobAcquireWaitTimeInMillis(springAsyncExecutorProperties.getDefaultTimerJobAcquireWaitTimeInMillis());
        springAsyncExecutor.setMaxTimerJobsPerAcquisition(springAsyncExecutorProperties.getMaxTimerJobsPerAcquisition());
        springAsyncExecutor.setMaxAsyncJobsDuePerAcquisition(springAsyncExecutorProperties.getMaxAsyncJobsDuePerAcquisition());
        springAsyncExecutor.setLockOwner(springAsyncExecutorProperties.getLockOwner());
        springAsyncExecutor.setResetExpiredJobsInterval(springAsyncExecutorProperties.getResetExpiredJobsInterval());
        springAsyncExecutor.setResetExpiredJobsPageSize(springAsyncExecutorProperties.getResetExpiredJobsPageSize());
        springAsyncExecutor.setQueueSize(springAsyncExecutorProperties.getQueueSize());
        return this.baseSpringProcessEngineConfiguration(dataSource, transactionManager, springAsyncExecutor);
    }

}
